package com.xy.biz.base.domain.converter;

import com.xy.biz.base.domain.bo.EquipmentBO;
import com.xy.biz.base.domain.po.EquipmentPO;
import com.xy.biz.base.domain.query.EquipmentQuery;
import com.xy.biz.base.domain.req.ListEquipmentRequest;
import com.xy.biz.base.domain.req.SaveEquipmentRequest;
import com.xy.biz.base.domain.resp.GetEquipmentResponse;
import com.xy.tool.util.BeanUtilsEx;

import java.util.Collection;
import java.util.List;

/**
 *
 *
 * @author yzh
 * @date 2021-4-13
 */
public class EquipmentConverter {

	public static EquipmentPO toPO(EquipmentBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new EquipmentPO(), true);
	}

	public static List<EquipmentPO> toPO(Collection<EquipmentBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new EquipmentPO(), true);
	}

	public static EquipmentBO fromPO(EquipmentPO source) {
		return BeanUtilsEx.copyProperties(source, () -> new EquipmentBO());
	}

	public static List<EquipmentBO> fromPO(Collection<EquipmentPO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new EquipmentBO());
	}

	public static EquipmentBO toBO(SaveEquipmentRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new EquipmentBO(), true);
	}

	public static List<EquipmentBO> toBO(Collection<SaveEquipmentRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new EquipmentBO(), true);
	}

	public static GetEquipmentResponse toResponse(EquipmentBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new GetEquipmentResponse());
	}

	public static List<GetEquipmentResponse> toResponse(Collection<EquipmentBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetEquipmentResponse());
	}

	public static EquipmentQuery toQuery(ListEquipmentRequest source) {
		if(null == source) {
			return null;
		}
		EquipmentQuery target = new EquipmentQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
